From bf6400a882e491140d73e2c287b576c7ef2c12d3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 10 Aug 2014 21:01:59 -0700 Subject: [PATCH] Fix `cargo clean` when not in the root dir Closes #361 --- src/cargo/util/toml.rs | 4 ++-- tests/test_cargo_clean.rs | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index a7a959f99..d160fef2a 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -391,8 +391,8 @@ impl TomlManifest { Ok((Manifest::new( &summary, targets.as_slice(), - &Path::new("target"), - &Path::new("doc"), + &layout.root.join("target"), + &layout.root.join("doc"), sources, match project.build { Some(SingleBuildCommand(ref cmd)) => vec!(cmd.clone()), diff --git a/tests/test_cargo_clean.rs b/tests/test_cargo_clean.rs index 4e4c13e5a..181ff7825 100644 --- a/tests/test_cargo_clean.rs +++ b/tests/test_cargo_clean.rs @@ -1,4 +1,4 @@ -use support::{project, execs, main_file, basic_bin_manifest}; +use support::{project, execs, main_file, basic_bin_manifest, cargo_dir}; use hamcrest::{assert_that, existing_dir, is_not}; fn setup() { @@ -9,9 +9,25 @@ test!(cargo_clean_simple { .file("Cargo.toml", basic_bin_manifest("foo").as_slice()) .file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice()); - assert_that(p.cargo_process("cargo-build"), execs()); + assert_that(p.cargo_process("cargo-build"), execs().with_status(0)); assert_that(&p.build_dir(), existing_dir()); - assert_that(p.cargo_process("cargo-clean"), execs()); + assert_that(p.process(cargo_dir().join("cargo-clean")), + execs().with_status(0)); + assert_that(&p.build_dir(), is_not(existing_dir())); +}) + +test!(different_dir { + let p = project("foo") + .file("Cargo.toml", basic_bin_manifest("foo").as_slice()) + .file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice()) + .file("src/bar/a.rs", ""); + + assert_that(p.cargo_process("cargo-build"), execs().with_status(0)); + assert_that(&p.build_dir(), existing_dir()); + + assert_that(p.process(cargo_dir().join("cargo-clean")) + .cwd(p.root().join("src")), + execs().with_status(0).with_stdout("")); assert_that(&p.build_dir(), is_not(existing_dir())); }) -- 2.30.2